package com.bogewang.s2sh.service.impl;

import com.bogewang.s2sh.dao.IUserDao;
import com.bogewang.s2sh.model.User;
import com.bogewang.s2sh.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("userService")
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao<User> userDao;

    @Override
    public void saveUser(User user) {
        userDao.save(user);

    }

    @Override
    public void updateUser(User user) {
        this.userDao.update(user);
    }

    @Override
    public User findUserById(Integer id) {
        return this.userDao.get(User.class, id);
    }

    @Override
    public void deleteUser(User user) {
        userDao.delete(user);
    }

    @Override
    public List<User> findAllList() {
        String hql = "from User u order by u.createTime";
        return userDao.find(hql);
    }

    @Override
    public User findUserByNameAndPassword(String username, String password) {
        String hql = "from User u where u.userName = ? and u.password=?";
        return userDao.get(hql, new Object[]{username, password});
    }
}
